package com.lingtianyu.tech.erbaoshen.core.config;

import com.lingtianyu.tech.erbaoshen.core.provider.bean.ErBaoShenRpcServiceBeans;
import com.lingtianyu.tech.erbaoshen.core.provider.bean.ServiceBean;
import org.springframework.boot.CommandLineRunner;

import javax.annotation.Resource;

//@Component
//@Order(2)
public class ErBaoShenBeanCommandLineRunner implements CommandLineRunner {
    @Resource(name = "erBaoShenRpcServiceBeans")
    private ErBaoShenRpcServiceBeans erBaoShenRpcServiceBeans;

    @Override
    public void run(String... args) throws Exception {
        //注册远程provider
        String[] beanNames = ErBaoShenRpcApplicationContextAware.getApplicationContext().getBeanNamesForType(ServiceBean.class);
        for (String beanName : beanNames) {
            ServiceBean bean = (ServiceBean) ErBaoShenRpcApplicationContextAware.getApplicationContext().getBean(beanName);
            String group = bean.getGroup() != null ? bean.getGroup() : "";
            String version = bean.getVersion() != null ? bean.getVersion() : "";
            String key = bean.getInterfaceClass().getTypeName() + ":" + group + ":" + version;
            erBaoShenRpcServiceBeans.putServiceBeanMap(key, bean, beanName);
        }

        //注册远程consumer
    }
}
